import { UITransform } from 'cc';
import { Sprite } from 'cc';
import { CCInteger } from 'cc';
import { SpriteFrame } from 'cc';
import { Size } from 'cc';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('DiceStamp')
@executeInEditMode(true)
export class DiceStamp extends Component {
  @property(SpriteFrame)
  diceFaces: SpriteFrame[] = [];


  @property(Size)
  _diceSize: Size = new Size(100, 100);
  @property(Size)
  get diceSize() {
    return this._diceSize;
  }
  set diceSize(value: Size) {
    this._diceSize = value;
    this.node.getComponent(UITransform).setContentSize(value);
  }

  @property(CCInteger)
  _value: number = 1;
  @property(CCInteger)
  get value() {
    return this._value;
  }
  set value(value: number) {
    this._value = value;
    this.updateUI();
  }

  updateUI() {
    let sprite = this.node.getComponent(Sprite);
    sprite.spriteFrame = this.diceFaces[this.value - 1];
    if (this.value < 1 || this.value > 6) {
      this.node.active = false;
    } else {
      this.node.active = true;
    }
  }


  start() {

  }

  update(deltaTime: number) {

  }
}


